namespace CaltechSoft.Service.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddProcedure : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.ProcedureItems",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ProcedureId = c.Int(nullable: false),
                        StandardId = c.Int(nullable: false),
                        CreatedBy = c.String(maxLength: 128),
                        CreatedDate = c.DateTime(),
                        UpdatedDate = c.DateTime(),
                        UpdatedBy = c.String(),
                        Equipment_CertificateStandardId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.CertificateStandard", t => t.Equipment_CertificateStandardId)
                .ForeignKey("dbo.Procedures", t => t.ProcedureId, cascadeDelete: true)
                .ForeignKey("dbo.AspNetUsers", t => t.CreatedBy)
                .Index(t => t.ProcedureId)
                .Index(t => t.CreatedBy)
                .Index(t => t.Equipment_CertificateStandardId);
            
            CreateTable(
                "dbo.Procedures",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ProcedureName = c.String(),
                        CreatedBy = c.String(maxLength: 128),
                        CreatedDate = c.DateTime(),
                        UpdatedDate = c.DateTime(),
                        UpdatedBy = c.String(maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AspNetUsers", t => t.UpdatedBy)
                .ForeignKey("dbo.AspNetUsers", t => t.CreatedBy)
                .Index(t => t.CreatedBy)
                .Index(t => t.UpdatedBy);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.ProcedureItems", "CreatedBy", "dbo.AspNetUsers");
            DropForeignKey("dbo.Procedures", "CreatedBy", "dbo.AspNetUsers");
            DropForeignKey("dbo.ProcedureItems", "ProcedureId", "dbo.Procedures");
            DropForeignKey("dbo.Procedures", "UpdatedBy", "dbo.AspNetUsers");
            DropForeignKey("dbo.ProcedureItems", "Equipment_CertificateStandardId", "dbo.CertificateStandard");
            DropIndex("dbo.Procedures", new[] { "UpdatedBy" });
            DropIndex("dbo.Procedures", new[] { "CreatedBy" });
            DropIndex("dbo.ProcedureItems", new[] { "Equipment_CertificateStandardId" });
            DropIndex("dbo.ProcedureItems", new[] { "CreatedBy" });
            DropIndex("dbo.ProcedureItems", new[] { "ProcedureId" });
            DropTable("dbo.Procedures");
            DropTable("dbo.ProcedureItems");
        }
    }
}
